package com.stylefeng.guns.modular.owBackstageMgr.memberMgr.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.modular.system.model.Member;
import com.stylefeng.guns.modular.system.dao.MemberMapper;
import com.stylefeng.guns.modular.owBackstageMgr.memberMgr.service.IMemberService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 会员表 服务实现类
 * </p>
 *
 * @author huangyuehong123
 * @since 2018-06-25
 */
@Service
public class MemberServiceImpl extends ServiceImpl<MemberMapper, Member> implements IMemberService {

    // “个人”、“单位”
    private Integer PERSONAL = 0;
    private Integer UNIT = 1;

    // "理事"、"监事"
    private Integer COUNCIL = 2;
    private Integer SUPERVISOR = 3;

    @Override
    public List<Map<String, Object>> getAllMembers(Page<Member> page, String condition, String orderByField, boolean asc) {
        return this.baseMapper.getAllMembers(page,condition,orderByField,asc);
    }

    // 获取num条会员（排除理事）的记录
    @Override
    public List<Member> getMembers(Integer num) {
        EntityWrapper<Member> wrapper = new EntityWrapper<>();
        wrapper.notIn("type",2);// 2代表“理事”类别
        wrapper.notIn("type",3);// 3代表“监事”类别
        wrapper.eq("is_del",0);
        wrapper.orderBy("orderval",true);
        wrapper.last("limit " + num);
        List<Member> memberList = selectList(wrapper);

        return memberList;
    }

    // 获取某一类别的会员的个数
    @Override
    public Integer getCountOfType(Integer type) {
        return this.baseMapper.getCountByType(type);
    }

    // 获取会员个数（排除“理事”）
    @Override
    public Integer getCountOfMember() {
        return getCountOfType(PERSONAL) + getCountOfType(UNIT);
    }


    // 获取理事会记录
    @Override
    public List<Member> getComittees(Integer type,Integer num) {
        EntityWrapper<Member> wrapper = new EntityWrapper<>();
        wrapper.eq("type",type);// 2代表“理事”类别
        wrapper.eq("is_del",0);
        wrapper.orderBy("orderval",true);

        if (num != null){
            wrapper.last("limit " + num);
        }

        List<Member> comitteeList = selectList(wrapper);

        return comitteeList;
    }


}
